package com.study.mike.common;

import com.study.mike.common.annotation.MyAnnotation;
import com.study.mike.model.entity.MyAnnotationDTO;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

import java.lang.reflect.Field;


/**
 * @author kh
 */
@SpringBootTest
public class Annotation {
    @Test
    void test() throws NoSuchFieldException {
        // 获取自定义属性值
        MyAnnotationDTO myAnnotationDTO = MyAnnotationDTO.builder().build();
//        MyAnnotationDTO myAnnotationDTO = new MyAnnotationDTO();
//        myAnnotationDTO.setUserName("我的名字");
//        System.out.println(myAnnotationDTO.getUserName());
//        Field userName = MyAnnotationDTO.class.getDeclaredField("userName");
//        userName.setAccessible(true);
//        MyAnnotation annotation = userName.getAnnotation(MyAnnotation.class);
//        System.out.println(annotation.userName());
//        System.out.println(userName.getName());

        Class clazz = myAnnotationDTO.getClass();
        //获取该对象上Info类型的注解
        MyAnnotation info = (MyAnnotation) clazz.getAnnotation(MyAnnotation.class);
        System.out.println("姓名：" + info.userName() +  "-----删除状态：" + info.isDelete() );
    }
}
